package huixue.cn.com.rxapp.kchart.presenter;

import java.util.List;

import huixue.cn.com.library.entity.BaseResponse;
import huixue.cn.com.library.observer.SimpleObserver;
import huixue.cn.com.rxapp.api.RetrofitService;
import huixue.cn.com.rxapp.base.BasePresent;
import huixue.cn.com.rxapp.base.IBaseUI;
import huixue.cn.com.rxapp.entity.HttpResult;
import huixue.cn.com.rxapp.helper.RxSchedulersHelper;
import huixue.cn.com.rxapp.kchart.bean.KLineData;
import huixue.cn.com.rxapp.util.HttpUiTips;
import huixue.cn.com.rxapp.util.LogUtils;

/**
 * Created by gongdongyang 2019/7/23
 * Describe:
 */
public class KChartPresenter extends BasePresent<KChartPresenter.KChartUI> {

    public interface KChartUI extends IBaseUI{

    }

    /**
     *
     * @param symbol
     * @param interval
     * @param from
     * @param to
     */
    public void loadNetWorkData(String symbol,String interval,long from, long to){

        HttpUiTips.showDialog(getActivity(),true, "loading...");

        SimpleObserver simpleObserver = new SimpleObserver<BaseResponse<List<KLineData>>>(){
            @Override
            public void onNext(BaseResponse<List<KLineData>> result) {
                super.onNext(result);
                HttpUiTips.dismissDialog(getActivity());
                LogUtils.d("KChartPresenter","size=="+result.data.size());
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                LogUtils.d("KChartPresenter","onError"+e.getLocalizedMessage());
                HttpUiTips.dismissDialog(getActivity());
            }
        };

        RetrofitService
                .loadKLineDataV(symbol,interval,String.valueOf(from),String.valueOf(to))
                .compose(RxSchedulersHelper.io_main(getmUI()))
                .subscribe(simpleObserver);
    }

}
